package com.yun;

import com.yun.entity.UserInfo;
import com.yun.mapper.UserInfoMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 * @Author: fxy
 * @Date: 2022/05/17/8:15
 * @Description:
 */
public class Test1 {
  public static void main(String[] args) throws IOException {
    String resource = "mybatis-config.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    SqlSession sqlSession = sqlSessionFactory.openSession();
    UserInfo blog = sqlSession.selectOne("com.yun.mapper.UserInfoMapper", 101);
    System.out.println(blog);
  }
  @Test
  public void t1() throws IOException {
    String resource = "mybatis-config.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    SqlSession sqlSession = sqlSessionFactory.openSession();
    UserInfoMapper mapper = sqlSession.getMapper(UserInfoMapper.class);
    UserInfo select = mapper.select("101");
    System.out.println(select);
  }

  @Test
  public void t2() throws IOException {
    String resource = "mybatis-config.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    SqlSession sqlSession = sqlSessionFactory.openSession();
    UserInfoMapper mapper = sqlSession.getMapper(UserInfoMapper.class);
    Map select = mapper.selectUserMap();
    System.out.println(select);
  }

  @Test
  public void selectParam() throws IOException {
    String resource = "mybatis-config.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

    SqlSession sqlSession = sqlSessionFactory.openSession();
    //sqlSessionFactory.openSession(true);
    UserInfoMapper mapper = sqlSession.getMapper(UserInfoMapper.class);
    List<UserInfo> select = mapper.selectByName(null,null);
    //List<UserInfo> select2 = mapper.selectByName(null,null);
    //sqlSession.commit();
    //sqlSession.close();
    System.out.println(select);
  }
}
